package com.burns.strawberry.service.impl;/**
 * Created by burns.
 *
 * @author <a href="http://www.esoon-soft.com/">burns</a>
 * @date 2020/12/06 22:57
 */

import com.burns.strawberry.mapper.UserMapper;
import com.burns.strawberry.po.User;
import com.burns.strawberry.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author Burns
 * @DAte 2020/12/6 22:57
 * @Version 1.0
 **/
@Service
@Transactional
public class UserServiceImpl implements UserService {

    //注入用户Mappper
    @Autowired
    private UserMapper userMapper;

    //查询所有用户
    @Override
    @Cacheable(value = "UserCache",key = "'user.getAllUsers'")
    public List<User> getAllUsers() {
        return this.userMapper.getAllUsers();
    }

    //删除用户
    @Override
    @CacheEvict(value = "UserCache",key = "'user.getAllUsers'")
    public void deleteUser(Integer id) {
        System.out.println("删除了id为"+id+"的用户");
        this.userMapper.delete(id);
    }
}
